// 退出功能
const logout = document.querySelector('.logout');
logout.addEventListener('click', function () {
  const flag = confirm('是否退出');
  if (flag) {
    localStorage.removeItem('token');
    location.href = './login.html';
  }
});

// 侧边栏关闭展开功能
const sidelist = document.querySelectorAll('.nav>li>a');
const sideActiveA = document.querySelectorAll('.nav ul a');
sidelist.forEach((item) => {
  item.addEventListener('click', function () {
    item.querySelector('.toggle').classList.toggle('toggleone');
    this.nextElementSibling.classList.toggle('show');
  });
});
sideActiveA.forEach((item) => {
  item.addEventListener('click', function () {
    // 先去除已经激活的a标签
    document.querySelector('.nav ul a.active').classList.remove('active');
    item.classList.add('active');
  });
});

// 请求初始化数据
const studentInitData = document.querySelector('.init');
studentInitData.addEventListener('click', function () {
  console.log(11);
  axios.get('/init/data').then((res) => {
    console.log(res);
    if (res.data.code === 0) {
      toastr.success(res.data.message);
    }
  });
});
